package com.xihuanjun.util;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

/**
 * @author: 江溪浣
 * @createDate: 2022/10/26 10:27
 * @description:
 */
@Data
@ConfigurationProperties(prefix = "xihuanjun.upload")
public class UploadUtils {
    private String savePath;

    /**
     * 保存上传过来的一个文件到存储目录
     * @param file
     * @param fileName 文件名，带扩展名
     */
    public boolean saveFile(MultipartFile file,String fileName){
        File newfile=new File(savePath,fileName);
        try {
            file.transferTo(newfile);
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
